﻿using AutoMapper;
using Modules.System.AppNotice;
using PmSoft;

namespace ManagementApi.Models.System.AppNotice
{
    public class AppNoticeInfoDto
    {
        /// <summary>
        ///  主键Id
        ///</summary>
        public int Id { get; set; }
        public 通知公告类型 NoticeType { get; set; }
        public string NoticeTypeName { get; set; }
        /// <summary>
        /// 标题 
        ///</summary>
        public string Title { get; set; }
        /// <summary>
        /// 内容 
        ///</summary>
        public string Content { get; set; }
        /// <summary>
        /// 是否置顶 1=指定 0=不置顶 
        /// 默认值: b'0'
        ///</summary>
        public string IsTop { get; set; }
        /// <summary>
        /// 是否删除 0=未删除 1=已删除 
        /// 默认值: b'0'
        ///</summary>
        public int IsDeleted { get; set; }
        /// <summary>
        /// 创建时间 
        ///</summary>
        public DateTime CreateTime { get; set; }
        /// <summary>
        ///  
        ///</summary>
        public DateTime? UpdateTime { get; set; }
    }

    public static partial class AppNoticeInfoExceptions
    {
        /// <summary>
        /// APP通知公告
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static AppNoticeInfoDto AsAppNoticeInfoDto(this AppNoticeInfo entity)
        {
            var mapper = ServiceAccessor.GetService<IMapper>();
            AppNoticeInfoDto dto = new AppNoticeInfoDto();
            mapper.Map(entity, dto);
            dto.IsTop = entity.IsTop ? "已置顶" : "未置顶";
            dto.NoticeTypeName = entity.NoticeType.GetDescription();
            return dto;
        }
    }
}
